package xyz.worldzhile.chatroom.controller;


import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.worldzhile.chatroom.domain.User;
import xyz.worldzhile.chatroom.vo.Result;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {

    @RequestMapping("/login")
    //bleException: Required request body is missing
    public Result login(@RequestBody User user, HttpSession httpSession){
        Result result = new Result();

        if (user!=null&&user.getUserName()!=null&&"123".equals(user.getPassword())){
            result.setFlag(true);
            httpSession.setAttribute("user",user.getUserName());
        }else {
            result.setFlag(false);
            result.setMessage("用户名或密码错误!");
        }
       return result ;
    }

/*    @RequestMapping("/getUserName")
    public Map<String,String> getUserName(HttpSession httpSession){
        Map<String, String> objectObjectHashMap = new HashMap<>();

//        return (String) httpSession.getAttribute("user");
        objectObjectHashMap.put("code","200");
        objectObjectHashMap.put("user",(String) httpSession.getAttribute("user"));
        return objectObjectHashMap;
    }*/

    @RequestMapping("/getUserName")
    public String getUserName(HttpSession httpSession){
        return (String) httpSession.getAttribute("user");
    }
}
